package cn.tx.util;

import cn.tx.dao.ClazzDao;
import cn.tx.dao.TeDao;
import cn.tx.dao.GradeDao;
import cn.tx.model.Clazz;
import cn.tx.model.Grade;
import cn.tx.model.Te;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RunWith(SpringJUnit4ClassRunner.class)// 添加spring测试方案
@ContextConfiguration("/config/spring/applicationContext.xml")// 指定spring配置文件位置
public class MyBatisTest {


    @Autowired
    private TeDao teDao;

//   for(int i = 15;i<25;i++){}
    @Test
    public void testInsert2() {
        Te m = new Te();
        m.setid(7L);
        m.setname("zhang");
        m.setsex("男");
        teDao.addTe(m);
    }

    //
    @Test
    public void testInsert() {
        Te c = new Te();
        c.setname("2021");

        teDao.addTe(c);
    }
    @Test
    public void testUpdate() {
        Te c = new Te();
        c.setid(2L);
        c.setname("zhang");
        c.setsex("测试组程序修改");
        teDao.updateTeById(c);

    }
    @Test
    public void testDelete() {
        teDao.delete("12");
    }
    @Test
    public void testSelect() {
        List<Te> list =  teDao.findAll();
        for(Te c:list){
            System.out.println(c.getname()+"---"+c.getsex());
        }
    }
    @Test
    public void testSelect1() {
        Map<String,Object> temap = new HashMap<String,Object>();
        temap.put("name","%zhang%");
        temap.put("offset", 1);
        temap.put("pageSize", 5);
        List<Te> list = teDao.findList(temap);
        for(Te c:list){
            System.out.println(c.getid()+"---"+c.getname()+"---"+c.getsex());
        }
    }


}
